using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace Gigaframe
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class DataSystemService : System.Web.Services.WebService
    {

        [WebMethod]
        public object GetData(string databaseName, string tableName, string rowKey, string columnName)
        {
            System.Configuration.AppSettingsReader s = new System.Configuration.AppSettingsReader();

            Gigaframe.DataSystem ds = new Gigaframe.DataSystem((string)s.GetValue("DatabaseRootPath", Type.GetType("System.String")));

            return ds.GetData(databaseName, tableName, rowKey, columnName);
        }

        [WebMethod]
        public bool SetData(string databaseName, string tableName, string rowKey, string columnName, object data, Gigaframe.DataSystem.DataTypes datatype)
        {
            System.Configuration.AppSettingsReader s = new System.Configuration.AppSettingsReader();

            Gigaframe.DataSystem ds = new Gigaframe.DataSystem((string)s.GetValue("DatabaseRootPath", Type.GetType("System.String")));

            return ds.SetData(databaseName, tableName, rowKey, columnName, data, datatype);
        }

        [WebMethod]
        public DataSet GetDataSet(string databaseName, string tableName, string whereClause, string sortClause)
        {
            DataSet retds = new DataSet();
            DataTable dt = null;
            
            System.Configuration.AppSettingsReader s = new System.Configuration.AppSettingsReader();

            Gigaframe.DataSystem ds = new Gigaframe.DataSystem((string)s.GetValue("DatabaseRootPath", Type.GetType("System.String")));

            dt = ds.GetDataTable(databaseName, tableName, whereClause, sortClause);

            if(dt != null)
                retds.Tables.Add(dt);

            return retds;
        }
    }
}
